﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using IAM.Interface.DAL;
using IAM.Interface.IDAL;
using IAM.Interface.Model;
using IAM.Interface.Model.ENUM;
using System.Xml;
using IAM.Interface.Common.Context;
using IAM.Interface.Common.Abnormity;


public partial class Response : System.Web.UI.Page
{
    #region Page_Load
    protected void Page_Load(object sender, EventArgs e)
    {
        TransactData();
    }
    #endregion

    #region 数据处理
    /// <summary>
    /// 数据处理
    /// 0.实例化响应端发送消息上下文控制对象
    /// 0.1判断请求ip是否安全
    /// 1.接收xml请求
    /// 1.1加密类型
    /// 1.2密钥
    /// 1.3xml信息
    /// 2.实例化ResponseContextModel
    /// 4.响应端处理，返回xml包
    /// 5.回写数据流
    /// </summary>
    private void TransactData()
    {
        try
        {

            //实例化响应端发送消息上下文控制对象
            ResponseContextControl rcc = new ResponseContextControl();
            //0.1判断请求ip是否安全
            bool validate = rcc.ValidateRequestIP();
            if (!validate)
            {
                ResponseException rex = new ResponseException();
                rex.StatusCode = 418;
                throw (rex);
            }
            //1.接收xml请求
            //1.3xml信息
            string xmlinfo = Request.Form["xml"];
            string key = ResponseContextControl.GetConfigKey();
            //1.4 签名 
            string sign = "";

            sign = Request.Form["sign"];
            //2.实例化ResponseContextModel
            ResponseContextModel rcm = new ResponseContextModel(
                                                                sign,
                                                                0,
                                                                key,
                                                                xmlinfo);
            //3.实例化响应端发送消息上下文控制对象
            rcc.ContextModel = rcm;


            //4.响应端处理，返回xml包
            string strresult = rcc.ContextControl();
            //5.回写数据流
            Response.Write(strresult);
        }
        catch (ResponseException re)
        {
            throw (re);
        }
        catch (Exception ex)
        {
            throw (ex);
        }
    }
    #endregion
}
